package com.answer.model.vo;

import cn.hutool.json.JSONUtil;
import com.answer.model.dto.question.QuestionContentDTO;
import com.answer.model.entity.Question;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 题目
 * @TableName question
 */
@Data
public class QuestionVo implements Serializable {
    /**
     * id
     */
    private Long id;

    /**
     * 题目内容
     */
    private List<QuestionContentDTO> questionContentDTO;

    /**
     * 这套题目的标题
     */
//    private String topic;

    /**
     * 应用 id
     */
    private Long appId;

    /**
     * 创建用户
     */
    private UserVo userVo;

    /**
     * 创建时间
     */
    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 更新时间
     */
    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    private static final long serialVersionUID = 1L;


    public static QuestionVo objToVo(Question question){
        QuestionVo questionVo = new QuestionVo();
        BeanUtils.copyProperties(question, questionVo);
        List<QuestionContentDTO> questionContentDTOS = JSONUtil.toList(question.getQuestionContent(), QuestionContentDTO.class);
        questionVo.setQuestionContentDTO(questionContentDTOS);
        return questionVo;
    }
}